﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace StarForce {
    public class UiMotionMovementCard : UiMotionBaseCard
    {
        public UiMotionMovementCard(Card handler,bool withZ = false) : base(handler) {
            
        }

        /// <summary>
        /// 是否固定z值
        /// </summary>
        private bool WithZ { get; set; }

        protected override void OnMotionEnds() {
            WithZ = false;
            IsOperating = false;
            Vector3 target = Target;
            target.z = Handler.transform.position.z;
            Handler.transform.position = target;
            base.OnMotionEnds();
        }

        protected override bool CheckFinslState() {
            Vector3 distance = Target - Handler.transform.position;
            if (!WithZ)
                distance.z = 0;
            return distance.magnitude <= Threshold;
        }

        protected override void KeepMotion() {
            Vector3 current = Handler.transform.position;
            float speed = Speed * Time.deltaTime;
            Vector3 delta = Vector3.Lerp(current, Target, speed);
            if (!WithZ) {
                delta.z = Handler.transform.position.z;
            }
            Handler.transform.position = delta;
        }

        public override void Execute(Vector3 vector, float speed, float delay, bool withZ = false) {
            WithZ = withZ;
            base.Execute(vector, speed, delay, withZ);
        }
    }
}

